package com.avic.system.common.convertor;


import com.avic.system.controller.info.SystemPermissionInfo;
import com.avic.system.dal.model.SystemPermission;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 系统权限对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemPermissionConvertor {

    /**
     * 将 SystemPermissionDO 转换为 SystemPermissionInfo
     *
     * @author: huangsheng
     * @date: 2017/10/24 上午10:48
     */
    public static SystemPermissionInfo convertToSystemPermissionInfo(final SystemPermission systemPermission) {
        if (null == systemPermission) {
            return null;
        }
        SystemPermissionInfo systemPermissionInfo = new SystemPermissionInfo();
        systemPermissionInfo.setPermissionId(systemPermission.getId());
        systemPermissionInfo.setPermissionName(systemPermission.getPermissionName());
        systemPermissionInfo.setPermissionCode(systemPermission.getPermissionCode());
        return systemPermissionInfo;
    }

    /**
     * 将 SystemPermissionDOs 转换为 SystemPermissionInfos
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemPermissionInfo> convertToSystemPermissionInfoss(final List<SystemPermission> systemPermissions) {
        List<SystemPermissionInfo> systemPermissionInfos = new ArrayList<>();
        if (null != systemPermissions && systemPermissions.size() > 0) {
            systemPermissions.forEach(systemPermission -> {
                systemPermissionInfos.add(SystemPermissionConvertor.convertToSystemPermissionInfo(systemPermission));
            });
            return systemPermissionInfos;
        }
        return Collections.emptyList();
    }

}
